home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Burning & Media / GB-PVR 1.2.13 / GBPVR10213.msi / Cabs.w1.cab / Admin.aspx.cs655 < prev    next >
Text File  |  2008-02-23  |  17KB  |  422 lines

  1. using System;
  2. using System.Collections;
  3. using System.IO;
  4. using System.Net;
  5. using System.Security.Cryptography;
  6. using System.Text;
  7. using System.Web;
  8. using System.Web.Security;
  9. using System.Web.UI;
  10. using System.Web.UI.HtmlControls;
  11. using GBPVR.Public;
  12. using GBPVRSchedule;
  13. using gbweb.classes;
  14.  
  15. namespace gbweb
  16. {
  17.     /// <summary>
  18.     /// Summary description for Admin.
  19.     /// </summary>
  20.     public partial class Admin : Page
  21.     {
  22.         protected HtmlInputText mimeType;
  23.     
  24.         private Settings guideParams;
  25.  
  26.         protected void Page_Load(object sender, EventArgs e)
  27.         {
  28.             //Code to prevent Guest users from accessing the Admin page directly by URL
  29.             if (!Convert.ToBoolean((string)Session["NotGuestUser"]))
  30.             {
  31.                 string hostAddress = string.Empty;
  32.                 string Url =
  33.                     Request.Url.ToString().Replace(Request.Url.Scheme + Uri.SchemeDelimiter + Request.Url.Authority,
  34.                                                    Request.Url.Scheme + Uri.SchemeDelimiter + Request.Headers["Host"]);
  35.  
  36.  
  37.                 string redirectUrl = Url.ToLower().Replace("admin.aspx", "guide.aspx");
  38.                 Logger.Info(" ");
  39.                 Logger.Info(" ");
  40.                 Logger.Info("Guest user trying to access the admin page......");
  41.                 Logger.Info("Pulling User IP Info...");
  42.                 if (Request.UserHostAddress.Substring(0, 1) == ":")
  43.                 {
  44.                     Logger.Info("IP V6 Detected");
  45.                     hostAddress = GetIP4Address();
  46.                     Logger.Info("IP6 Address: " + Request.UserHostAddress);
  47.                     Logger.Info("IP4 Address: " + hostAddress);
  48.                     Logger.Info(" ");
  49.                 }
  50.                 else
  51.                 {
  52.                     Logger.Info("IP V4 Detected");
  53.                     hostAddress = Request.UserHostAddress;
  54.                     Logger.Info("IP4 Address: " + hostAddress);
  55.                     Logger.Info(" ");
  56.                 }
  57.                 Logger.Info("Redirecting user to the guide");
  58.                 Logger.Info(" ");
  59.                 Logger.Info(" ");
  60.                 Response.Redirect(redirectUrl, true);
  61.             }
  62.  
  63.             Session["GuideStartTime"] = null;
  64.             if (User.Identity.Name.Length == 0)
  65.                 {
  66.                     FormsAuthentication.SignOut();
  67.                     Response.Redirect("Login.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.Url.PathAndQuery));
  68.                 }
  69.  
  70.             guideParams = Global.Settings;
  71.  
  72.             VLCCommon VLC = new VLCCommon(1);
  73.             VLCCommon VLC2 = new VLCCommon(2);
  74.             
  75.             if (!IsPostBack) 
  76.             {
  77.                 string[] themes = Directory.GetDirectories(Server.MapPath(Request.ApplicationPath + "/themes/"));
  78.                 //Create an array to hold the theme names so we can easily sort it later
  79.                 ArrayList themenames = new ArrayList();
  80.                 foreach (string theme in themes)
  81.                 {
  82.                     //Load each theme that is found in the themes directory to the array of names
  83.                     if (File.Exists(Path.Combine(theme, "styles.css")))
  84.                     {
  85.                         themenames.Add(Path.GetFileName(theme));
  86.                     }
  87.                 }
  88.                 //set the first theme in the list to Default
  89.                 dropdownThemes.Items.Add("Default");
  90.                 //Sort the loaded themes into alphabetical order
  91.                 themenames.Sort();
  92.                 //Add the sorted themnames to the dropdown list
  93.                 foreach (string s in themenames)
  94.                 {
  95.                     dropdownThemes.Items.Add(s);
  96.                 }
  97.             
  98.                 HttpCookie cookie = Request.Cookies["minuteSpan"];
  99.                 txtMinuteSpan.Value = cookie != null ? cookie.Value : "120";
  100.                 
  101.                 cookie = Request.Cookies["minuteInterval"];
  102.                 txtMinuteInterval.Value = cookie != null ? cookie.Value : "30";
  103.                 
  104.                 cookie = Request.Cookies["minuteSlice"];
  105.                 txtMinuteSlice.Value = cookie != null ? cookie.Value : "1";
  106.                 
  107.                 cookie = Request.Cookies["TimelineRepeat"];
  108.                 txtTimelineRepeat.Value = cookie != null ? cookie.Value : "10";
  109.  
  110.                 guideStartTime.Text = guideParams.guideStartTime;
  111.                 DateTime now = DateTime.Now;
  112.                 DateTime then = now.AddMinutes(Convert.ToDouble(guideParams.reminder));
  113.                 TimeSpan span = then - now;
  114.                 txtReminderDays.Value = span.Days.ToString();
  115.                 txtReminderHours.Value = span.Hours.ToString();
  116.                 txtReminderMinutes.Value = span.Minutes.ToString();
  117.  
  118.                 dropdownRecordingQuality.SelectedValue    = guideParams.recordingQuality.ToString();
  119.                 
  120.                 string themeName = Convert.ToString(Session["theme"]);
  121.                 if (themeName != null && themeName != "")
  122.                 {
  123.                     int themeIdx = themeName.IndexOf("/");
  124.                     if (themeIdx > 0)
  125.                     {
  126.                     themeName = themeName.Substring(themeIdx + 1, themeName.Length - (themeIdx + 1));
  127.                     dropdownThemes.SelectedValue = themeName;
  128.                     }
  129.                     else
  130.                     {
  131.                         dropdownThemes.SelectedValue  = "Default";
  132.                     }
  133.                 }
  134.                 else
  135.                 {
  136.                     dropdownThemes.SelectedValue = "Default";
  137.                 }
  138.  
  139.                 displayTabs.Items[0].Selected           = guideParams.showTVGuide;
  140.                 displayTabs.Items[1].Selected           = guideParams.showManage;
  141.                 displayTabs.Items[2].Selected           = guideParams.showSearch;
  142.                 displayTabs.Items[3].Selected           = guideParams.showVideoLib;
  143.                 displayTabs.Items[4].Selected           = guideParams.showMusicLib;
  144.                 displayTabs.Items[5].Selected           = guideParams.showPhotoLib;
  145.                 displayTabs.Items[6].Selected           = guideParams.showStats;
  146.                 showDescription.Checked                    = guideParams.showDescription;
  147.                 showDescription.Checked                    = guideParams.showDescription;
  148.                 showSubtitle.Checked                    = guideParams.showSubtitle;
  149.                 showGenre.SelectedValue                    = guideParams.showGenre;
  150.                 showRating.Checked                        = guideParams.showRating;
  151.                 showNew.Checked                            = guideParams.showNew;
  152.                 showIMDB.Checked                        = guideParams.showIMDB;
  153.                 showNetflix.Checked                        = guideParams.showNetflix;
  154.                 showTVCom.Checked                       = guideParams.showTVCom;
  155.                 showWiki.Checked                        = guideParams.showWiki;
  156.                 showCredits.Checked                        = guideParams.showCredits;
  157.                 showAirDate.Checked                        = guideParams.showAirDate;
  158.                 showStarRating.Checked                    = guideParams.showStarRating;
  159.                 showHD.Checked                          = guideParams.showHD;
  160.                 playlistExtension.Value                 = guideParams.playlistExtension;
  161.                 cookie                                  = Request.Cookies["useChannelIcons"];
  162.                 UseChannelIcons.SelectedValue           = cookie != null ? cookie.Value : "chnlText";
  163.                 autoShowSearch.SelectedValue            = guideParams.autoShowSearch.ToString();
  164.                 autoRecordSearch.SelectedValue          = guideParams.autoShowRecord.ToString();
  165.                 autoSearchEPGDays.Value                 = guideParams.autoSearchDays.ToString();
  166.                 
  167.                 
  168.                 cookie                                  = Request.Cookies["channelIconHeight"];
  169.                 txtChnlIconH.Value                      = cookie != null ? cookie.Value : "";
  170.                 cookie                                  = Request.Cookies["channelIconWidth"];
  171.                 txtChnlIconW.Value                      = cookie != null ? cookie.Value : "";
  172.                 
  173.                 txtAutologinList.Text                    = guideParams.autologinNetworks;
  174.  
  175.                 guestUser.Value                         = guideParams.GuestUser;
  176.                 guestPassword.Value                     = guideParams.GuestPassword;
  177.  
  178.                 //Web Streamer Variables
  179.                 
  180.                 streamPlayer.Text                       = guideParams.strmPlayer;
  181.                 externalPlayer.Checked                  = guideParams.strmExternal;
  182.                 streamPlayer2.Text                      = guideParams.strmPlayer2;
  183.                 externalPlayer2.Checked                 = guideParams.strmExternal2;
  184.  
  185.                 //Web Streamer VLC Common Class
  186.                 strmVLCLoc.Text                         = VLC.getVLCLoc();
  187.                 strmVLCLoc2.Text                        = VLC2.getVLCLoc();
  188.  
  189.                 spanExtendedEWA.Visible = ExtendedEWA.Initialize();
  190.                 
  191.             }
  192.             
  193.         }
  194.  
  195.         #region Web Form Designer generated code
  196.         override protected void OnInit(EventArgs e)
  197.         {
  198.             //
  199.             // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  200.             //
  201.             InitializeComponent();
  202.             base.OnInit(e);
  203.         }
  204.         
  205.         /// <summary>
  206.         /// Required method for Designer support - do not modify
  207.         /// the contents of this method with the code editor.
  208.         /// </summary>
  209.         private void InitializeComponent()
  210.         {
  211.  
  212.         }
  213.         #endregion
  214.  
  215.         protected void forceSearch_Click(object sender, EventArgs e)
  216.         {
  217.             SavedSearchUtils searchUtil = new SavedSearchUtils();
  218.             searchUtil.autoSearch(searchUtil.loadAutoSearches());
  219.         }
  220.  
  221.         protected void Kill_All_Reminders_Click(object sender, EventArgs e)
  222.         {
  223.             Schedule scheduleHelper = Global.Schedule;
  224.             ArrayList reminders = scheduleHelper.GetReminderList();
  225.             foreach (Programme programme in reminders)
  226.             {
  227.                 scheduleHelper.RemoveReminder(programme);
  228.             }
  229.         }
  230.  
  231.         protected void hlSubmit_Click(object sender, EventArgs e)
  232.         {
  233.             HttpCookie cookie = new HttpCookie("minuteSpan", txtMinuteSpan.Value);
  234.             cookie.Expires = DateTime.Now.AddYears(1);
  235.             Response.Cookies.Add(cookie);
  236.             
  237.             cookie = new HttpCookie("minuteInterval", txtMinuteInterval.Value);
  238.             cookie.Expires = DateTime.Now.AddYears(1);
  239.             Response.Cookies.Add(cookie);
  240.             
  241.             cookie = new HttpCookie("minuteSlice", txtMinuteSlice.Value);
  242.             cookie.Expires = DateTime.Now.AddYears(1);
  243.             Response.Cookies.Add(cookie);
  244.             
  245.             cookie = new HttpCookie("TimelineRepeat", txtTimelineRepeat.Value);
  246.             cookie.Expires = DateTime.Now.AddYears(1);
  247.             Response.Cookies.Add(cookie);
  248.  
  249.             guideParams.guideStartTime = guideStartTime.Text;
  250.  
  251.             double minutes = 0;
  252.  
  253.             try
  254.             {
  255.                 minutes = ((Convert.ToDouble(txtReminderDays.Value) * 24) * 60);  
  256.             }
  257.             catch
  258.             {
  259.                 minutes = 0;
  260.                 txtReminderDays.Value = "0";
  261.             }
  262.             
  263.             try
  264.             {
  265.                 minutes += (Convert.ToDouble(txtReminderHours.Value) * 60); 
  266.             }
  267.             catch
  268.             {
  269.                 minutes += 0;
  270.                 txtReminderHours.Value = "0";
  271.             }
  272.             
  273.             try
  274.             {
  275.                 minutes += Convert.ToDouble(txtReminderMinutes.Value); 
  276.             }
  277.             catch
  278.             {
  279.                 minutes += 0;
  280.                 txtReminderMinutes.Value = "0";
  281.             }
  282.  
  283.             guideParams.reminder = minutes.ToString();
  284.  
  285.             guideParams.recordingQuality = dropdownRecordingQuality.SelectedValue;
  286.             
  287.             //Save the selected theme to the cookie for future use as well as the Session for current use
  288.             cookie = new HttpCookie("theme", dropdownThemes.SelectedValue);
  289.             cookie.Expires = DateTime.Now.AddYears(1);
  290.             Response.Cookies.Add(cookie);
  291.  
  292.             Session["theme"] = "themes/" + dropdownThemes.SelectedValue; 
  293.             
  294.             guideParams.showTVGuide         = displayTabs.Items[0].Selected;
  295.             guideParams.showManage          = displayTabs.Items[1].Selected;
  296.             guideParams.showSearch          = displayTabs.Items[2].Selected;
  297.             guideParams.showVideoLib        = displayTabs.Items[3].Selected;
  298.             guideParams.showMusicLib        = displayTabs.Items[4].Selected;
  299.             guideParams.showPhotoLib        = displayTabs.Items[5].Selected;
  300.             guideParams.showStats           = displayTabs.Items[6].Selected;
  301.             guideParams.showDescription        = showDescription.Checked;
  302.             guideParams.showSubtitle        = showSubtitle.Checked;
  303.             guideParams.showGenre            = showGenre.SelectedValue;
  304.             guideParams.showRating            = showRating.Checked;
  305.             guideParams.showNew              = showNew.Checked;
  306.             guideParams.showIMDB            = showIMDB.Checked;
  307.             guideParams.showNetflix            = showNetflix.Checked;
  308.             guideParams.showTVCom           = showTVCom.Checked;
  309.             guideParams.showWiki            = showWiki.Checked;
  310.             guideParams.showCredits            = showCredits.Checked;
  311.             guideParams.showAirDate            = showAirDate.Checked;
  312.             guideParams.showStarRating        = showStarRating.Checked;
  313.             guideParams.showHD              = showHD.Checked;
  314.             guideParams.autoShowSearch      = Convert.ToBoolean(autoShowSearch.SelectedValue);
  315.             guideParams.autoShowRecord      = Convert.ToBoolean(autoRecordSearch.SelectedValue);
  316.             guideParams.autoSearchDays      = Convert.ToDouble(autoSearchEPGDays.Value);
  317.  
  318.             cookie = new HttpCookie("showTVGuide", displayTabs.Items[0].Selected.ToString());
  319.             cookie.Expires = DateTime.Now.AddYears(1);
  320.             Response.Cookies.Add(cookie);
  321.  
  322.             cookie = new HttpCookie("useChannelIcons", UseChannelIcons.SelectedValue);
  323.             cookie.Expires = DateTime.Now.AddYears(1);
  324.             Response.Cookies.Add(cookie);
  325.             
  326.             guideParams.playlistExtension    = playlistExtension.Value;
  327.             
  328.             cookie = new HttpCookie("channelIconHeight", txtChnlIconH.Value);
  329.             cookie.Expires = DateTime.Now.AddYears(1);
  330.             Response.Cookies.Add(cookie);
  331.             
  332.             cookie = new HttpCookie("channelIconWidth", txtChnlIconW.Value);
  333.             cookie.Expires = DateTime.Now.AddYears(1);
  334.             Response.Cookies.Add(cookie);
  335.             
  336.             guideParams.autologinNetworks    = txtAutologinList.Text;
  337.  
  338.             guideParams.GuestUser           = guestUser.Value;
  339.             guideParams.GuestPassword       = getMd5Hash(guestPassword.Value);
  340.  
  341.             //Web Streamer
  342.             guideParams.strmPlayer          = streamPlayer.Text;
  343.             guideParams.strmExternal        = externalPlayer.Checked;
  344.             guideParams.strmVLCLoc          = strmVLCLoc.Text;
  345.             guideParams.strmPlayer2         = streamPlayer2.Text;
  346.             guideParams.strmExternal2       = externalPlayer2.Checked;
  347.             guideParams.strmVLCLoc2         = strmVLCLoc2.Text;
  348.  
  349.             Global.Settings.Save();
  350.  
  351.             string[] invalidAutologinNetworks = guideParams.ParseAutologinNetworks();
  352.             if (invalidAutologinNetworks.Length > 0)
  353.             {
  354.                 lblAutologinWarning.Text = "WARNING: Invalid ranges: " + string.Join(",", invalidAutologinNetworks);
  355.             } 
  356.             else 
  357.             {
  358.                 lblAutologinWarning.Text = string.Empty;
  359.             }
  360.             Page.RegisterStartupScript("startupScript", "<script language=JavaScript>reload();</script>");
  361.         }
  362.  
  363.         static string getMd5Hash(string input)
  364.         {
  365.             // Create a new instance of the MD5CryptoServiceProvider object.
  366.             MD5 md5Hasher = MD5.Create();
  367.  
  368.             // Convert the input string to a byte array and compute the hash.
  369.             byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
  370.  
  371.             // Create a new Stringbuilder to collect the bytes
  372.             // and create a string.
  373.             StringBuilder sBuilder = new StringBuilder();
  374.  
  375.             // Loop through each byte of the hashed data 
  376.             // and format each one as a hexadecimal string.
  377.             for (int i = 0; i < data.Length; i++)
  378.             {
  379.                 sBuilder.Append(data[i].ToString("x2"));
  380.             }
  381.  
  382.             // Return the hexadecimal string.
  383.             return sBuilder.ToString();
  384.         }
  385.  
  386.         protected void sizeDefault_Click(object sender, EventArgs e)
  387.         {
  388.             txtChnlIconH.Value = string.Empty;
  389.             txtChnlIconW.Value = string.Empty;
  390.         }
  391.  
  392.         protected void hlAutologinInternal_Click(object sender, EventArgs e)
  393.         {
  394.             txtAutologinList.Text = "127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,169.254.0.0/16";
  395.         }
  396.  
  397.         protected void hlAutologinNone_Click(object sender, EventArgs e)
  398.         {
  399.             txtAutologinList.Text = "none";
  400.         }
  401.         protected void txtPort_TextChanged(object sender, EventArgs e)
  402.         {
  403.  
  404.         }
  405.  
  406.         public string GetIP4Address()
  407.         {
  408.             string strIP4Address = String.Empty;
  409.  
  410.             foreach (IPAddress objIP in Dns.GetHostAddresses(Dns.GetHostName()))
  411.             {
  412.                 if (objIP.AddressFamily.ToString() == "InterNetwork")
  413.                 {
  414.                     strIP4Address = objIP.ToString();
  415.                     break;
  416.                 }
  417.             }
  418.             return strIP4Address;
  419.         }
  420.     }
  421. }
  422.